package cn.aylog.controller;

import cn.aylog.po.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin
public class RestfulController {

    // RESTful api
    @RequestMapping(value = "/item/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public String getData(@PathVariable int id, HttpServletRequest request, HttpServletResponse response) {
//        response.setContentType("application/json;charset=UTF-8");
//        String accept = request.getHeader("Accept");
//        System.out.println(accept);
        String value = "-1";
        if(1 == id) {
            value = "这是1的数据";
        } else if (2 == id) {
            value = "这是2的数据";
        } else {
            value = "-1";
        }
        return value;
    }

    @PostMapping("/additem")
    public String addData(@RequestBody User user) {
        System.out.println(user);
        return "SUCCESS";
    }


}
